package com.leha.forum.lehare.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.util.Date;

@TableName("user_levels")  // 对应数据库表名
public class UserLevel {
    /**
     * 用户等级关联ID（数据库自增）
     */
    @TableId(value = "user_level_id", type = IdType.AUTO)
    private Integer userLevelId;

    /**
     * 用户ID
     */
    @TableField(value = "user_id")
    private Integer userId;

    /**
     * 等级ID
     */
    @TableField(value = "level_id")
    private Integer levelId;

    /**
     * 用户当前经验值（默认值0）
     */
    @TableField("experience")
    private Integer experience = 0;

    /**
     * 创建时间（自动填充）
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private Date createdAt;

    /**
     * 最后更新时间（自动填充）
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private Date updatedAt;

    /**
     * 关联的等级信息（非表字段）
     */
    @TableField(exist = false)
    private Level level;

    /**
     * 关联的用户信息（非表字段）
     */
    @TableField(exist = false)
    private User user;

    /**
     * 添加经验值的业务方法
     */
    public void addExperience(int points) {
        this.experience += points;
        // 不再需要手动更新，通过 FieldFill.INSERT_UPDATE 自动处理
    }

    // 带参数的构造函数
    public UserLevel(Integer userId, Integer levelId) {
        this.userId = userId;
        this.levelId = levelId;
    }

    // MyBatis-Plus 需要无参构造函数
    public UserLevel() {
    }

    public Integer getLevelId() {
        return levelId;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public Integer getExperience() {
        return experience;
    }

    public Integer getUserId() {
        return userId;
    }

    public Integer getUserLevelId() {
        return userLevelId;
    }

    public Level getLevel() {
        return level;
    }

    public User getUser() {
        return user;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public void setLevelId(Integer levelId) {
        this.levelId = levelId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public void setExperience(Integer experience) {
        this.experience = experience;
    }

    public void setUserLevelId(Integer userLevelId) {
        this.userLevelId = userLevelId;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    public void setUser(User user) {
        this.user = user;
    }
}